<template>
  <div class="login-container">

    <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">
      <div class="left">
        <img src="http://www-wms-java.itheima.net/img/title.ef005a7a.png" alt="">
        <el-form-item prop="name">
          <span class="el-icon-lock" />
          <el-input v-model="loginForm.name" class="Nainput" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item prop="passWord">
          <span class="el-icon-lock" />
          <el-input v-model="loginForm.passWord" class="Nainput" show-password placeholder="请输入密码" />
        </el-form-item>
        <div>
          <el-checkbox v-model="checked" style="margin-right:180px">记住密码</el-checkbox>
        </div>
        <button @click="loginFn">立即登录</button>
      </div>
      <!-- 右侧的背景图片 -->
      <div class="rightBgc" />
    </el-form>

  </div>
</template>

<script>
import { setToken } from '@/utils/auth'
export default {
  name: 'Login',
  data() {
    return {
      checked: false,
      loginForm: {
        name: '13800000002',
        passWord: '123456'
      },
      loginRules: {
        name: [
          {
            required: true, message: '请输入手机号', trigger: 'blur'
          },
          {
            pattern: /^1[3-9]\d{9}$/, message: '手机号格式不正确', trigger: 'blur'
          }
        ],
        passWord: [
          {
            required: true, message: '请输入密码', trigger: 'blur'
          },
          {
            max: 12, min: 6, message: '请输入6-12位的密码', trigger: 'blur'
          }
        ]
      }
    }
  },
  methods: {
    // handleLogin() {
    //   console.log(1)
    //   this.$refs.loginForm.validate(valid => {
    //     if (valid) {
    //       this.$store.dispatch('user/login', this.loginForm).then(() => {
    //         this.$router.push({ path: this.redirect || '/' })
    //       }).catch(() => {
    //       })
    //     } else {
    //       console.log('error submit!!')
    //       return false
    //     }
    //   })
    // },
    loginFn() {
      // this.$router.push('/')
      this.$refs.loginForm.validate((valid) => {
        if (!valid) return
        setToken('eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJiNTJlYWUxMS0yYWZiLTQwYjUtODg3NC01OTEwOGU0YjI0NjUiLCJzdWIiOiJ7XCJyb2xlXCI6XCJST0xFX0FETUlOXCIsXCJ0eXBlXCI6XCIyXCIsXCJ1c2VybmFtZVwiOlwiYWRtaW5cIn0iLCJpc3MiOiJhZG1pbiIsImlhdCI6MTYwNjM3MTA3NiwiZXhwIjoxNjA2OTc1ODc2fQ.pCl45pY_v2w8rZU8l60UI4cQx-Ufl7DRw0rZqhY8zeE')
        this.$router.push('/')
      }
      )
    }
  }

}
</script>

<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
$bg:#283443;
$light_gray:#fff;
$cursor: #000;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
    width: 230px;
    height: 50px;
    background-color: #f8f5f5;
  }
}
.left{
  float: left;
    width: 398px;
    height: 516px;
    background: #fff;
    border-radius: 34px 0 0 34px;
    margin: 0 auto;
    padding: 20px;
    text-align: center;
    img {
    margin-top: 60px;
    width: 150px;
    height: 64px;
    }
    button{
      margin-top: 20px;
      border: 0;
    width: 280px;
    height: 50px;
    background: #ffb200;
    border-radius: 8px;
    box-shadow: 0 2px 9px 1px rgb(255 178 0 / 47%);
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    color: #332929;
    line-height: 22px;
    }
    .el-form-item{
      margin-top: 40px;
    margin-left: 45px;
    width: 280px;
    height: 50px;
      .el-icon-lock{
        line-height: 50px;
        font-size: 25px;
      float: left;
      width: 50px;
      height: 50px;
      background: #eae7e7;
      border-radius: 8px 0 0 8px;
      }
      .Nainput{
    width: 230px;
    height: 50px;
    background-color: #f8f5f5;
    border-bottom-left-radius: 0;
    border-top-left-radius: 0;
      }
    }
}
/* reset element-ui css */
.rightBgc{
  width: 560px;
    height: 516px;
    background-position: 50%;
    background-repeat: no-repeat;
    background-size: cover;
  background-image: url(http://www-wms-java.itheima.net/img/contentBg.1321d126.png) ;
  position: relative;
  float: right;
}
.login-container {
  .el-input {
    display: inline-block;
    height: 47px;
    width: 85%;

    // input {
    //   background: transparent;
    //   border: 0px;
    //   -webkit-appearance: none;
    //   border-radius: 0px;
    //   padding: 12px 5px 12px 15px;
    //   color: $light_gray;
    //   height: 47px;
    //   caret-color: $cursor;

    //   &:-webkit-autofill {
    //     box-shadow: 0 0 0px 1000px $bg inset !important;
    //     -webkit-text-fill-color: $cursor !important;
    //   }
    // }
  }

  // .el-form-item {
  //   border: 1px solid rgba(255, 255, 255, 0.1);
  //   background: rgba(0, 0, 0, 0.1);
  //   border-radius: 5px;
  //   color: #454545;
  // }
}
</style>

<style lang="scss" scoped>
$bg:#ffffff;
$dark_gray:#889aa4;
$light_gray:#eee;

.login-container {
  min-height: 100%;
  width: 100%;
  background-color: $bg;
  overflow: hidden;

  .login-form {
    background-color: #fff;
    position: relative;
    width: 958px;
    height: 516px;
    position: absolute;
    left: 50%;
    top: 50%;
    margin: 0 auto;
    overflow: hidden;
    border-radius: 40px;
    box-shadow: 0 0 20px rgb(93 93 93 / 33%);
    transform: translate(-50%,-50%);
  }

  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;

    .title {
      font-size: 26px;
      color: $light_gray;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
}
</style>
